# -*- coding: utf-8 -*-
 
import hashlib
from base import UserCase, Runner, TestSuite

class Case(UserCase):
    def test_device_list(self):
        p = {
            'cpu_id': self.randchar(12),
            'name': self.randhan(8),
        }
        res = self.c.open('/api/device/create', p)
        self.assertEqual(res['code'], 0)

        p = {
            'cpu_id': self.randchar(12),
            'name': self.randhan(8),
        }
        res = self.c.open('/api/device/create', p)
        self.assertEqual(res['code'], 0)

        res = self.c.open('/api/device/list', {'orderBy': 'id', 'orderDesc': '1'})
        id_a = res['data']['itemList'][0]['id']

        res = self.c.open('/api/device/list', {'orderBy': 'id', 'orderDesc': '0'})
        id_b = res['data']['itemList'][0]['id']

        self.assertNotEqual(id_a, id_b)


    def test_device_list2(self):
        p = {
            'cpu_id': self.randchar(12),
            'name': self.randhan(8),
        }
        res = self.c.open('/api/device/create', p)
        self.assertEqual(res['code'], 0)

        res = self.c.open('/api/device/list', {'orderBy': 'create', 'orderDesc': '1'})
        self.assertEqual(res['code'], 0)



test_list = [
    'test_device_list',
    'test_device_list2',
]
Suite = TestSuite([Case(t) for t in test_list])


if __name__ == '__main__':
    Runner.run(Suite)



